﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Utils.App
{
    public class GameObjectList
    {
        List<GameObject> list = new List<GameObject>();


        public List<GameObject> List { get { return list; } }


        static public event EventHandler LifecicleCreateEvent;
        static public event EventHandler LifecicleDestroyEvent;

        public void Add(GameObject go)
        {
            list.Add(go);
            if (LifecicleCreateEvent != null)
            {
                LifecicleCreateEvent(go, new EventArgs());
            }
        }

        public void Remove(GameObject go)
        {
            list.Remove(go);
            if (LifecicleDestroyEvent != null)
            {
                LifecicleDestroyEvent(go, new EventArgs());
            }
        }

        public void RemoveAll()
        {
            foreach (GameObject go in list)
            {
                LifecicleDestroyEvent(go, new EventArgs());
            }
            list.Clear();
        }

        public void UpdateAll(float dTime)
        {
            foreach (GameObject go in list)
            {
                go.Update(dTime);
            }
        }
    }
}
